package ru.alexbykov.nopaginate.paginate;

import ohos.agp.components.BaseItemProvider;
import ohos.agp.components.ListContainer;

/**
 * Date: 12.08.2017
 * Time: 15:20
 * Project: NoPagination
 *
 * @author Alex Bykov
 * You can contact me at me@alexbykov.ru
 */
final class ScrollUtils {
    private ScrollUtils() {
    }

    static boolean isOnBottom(ListContainer listContainer, int loadingTriggerThreshold) {
        final int visibleItemCount = listContainer.getVisibleIndexCount();
        final int totalItemCount = listContainer.getChildCount();
        final int firstVisibleItemPosition = listContainer.getFirstVisibleItemPosition();
        // Check if end of the list is reached (counting threshold) or if there is no items at all
        return (totalItemCount - visibleItemCount) <= (firstVisibleItemPosition + loadingTriggerThreshold)
            || totalItemCount == 0;
    }

    static void fullScrollToBottom(ListContainer recyclerView, BaseItemProvider adapter) {
        recyclerView.scrollTo(adapter.getCount() - 1);
    }
}
